<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>AdminLTE 2 | Dashboard</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
    <!-- Bootstrap 3.3.7 -->
    <link rel="stylesheet" href="../bower_components/bootstrap/dist/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="../bower_components/font-awesome/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="../bower_components/Ionicons/css/ionicons.min.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="../dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. Choose a skin from the css/skins
         folder instead of downloading all of them to reduce the load. -->
    <link rel="stylesheet" href="../dist/css/skins/_all-skins.min.css">
    <!-- Morris chart -->
    <link rel="stylesheet" href="../bower_components/morris.js/morris.css">
    <!-- jvectormap -->
    <link rel="stylesheet" href="../bower_components/jvectormap/jquery-jvectormap.css">
    <!-- Date Picker -->
    <link rel="stylesheet" href="../bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <!-- Daterange picker -->
    <link rel="stylesheet" href="../bower_components/bootstrap-daterangepicker/daterangepicker.css">
    <!-- bootstrap wysihtml5 - text editor -->
    <link rel="stylesheet" href="../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <!-- Google Font -->
    <link rel="stylesheet"
          href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">
</head>
<body class="hold-transition skin-blue sidebar-mini">
<header class="main-header">
    <!-- Logo -->
    <a href="#" class="logo">
        <span class="logo-mini"><b>A</b>P</span>
        <span class="logo-lg"><b>Admin</b>Page</span>
    </a>
    <nav class="navbar navbar-static-top">
        <a href="#" class="sidebar-toggle" data-toggle="push-menu" role="button">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </a>

        <div class="navbar-custom-menu">
            <ul class="nav navbar-nav">
                <!-- Notifications: style can be found in dropdown.less -->
                <li class="dropdown notifications-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <i class="fa fa-bell-o"></i>
                        <span class="label label-warning" id="warning"
                              th:text="${session.warningMerches.size()}"></span>
                    </a>
                    <ul class="dropdown-menu ">
                        <li class="header" th:text="${session.warningMerches.size()}+'条商品库存数量达到警戒线'"></li>
                        <li>
                            <!-- inner menu: contains the actual data -->
                            <ul class="menu" th:each="m:${session.warningMerches}">
                                <li>
                                    <a href="#">
                                        <i class="fa fa-warning text-yellow"></i>
                                        <span th:text="${m.getMerchName()}"></span>
                                    </a>
                                </li>
                            </ul>
                        </li>
                        <li class="footer"><a href="#">View all</a></li>
                    </ul>
                </li>

                <!-- User Account: style can be found in dropdown.less -->
                <li class="dropdown user user-menu">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                        <span class="hidden-xs">Admin</span>
                    </a>
                </li>
            </ul>
        </div>
    </nav>
</header>
<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">
        <!-- sidebar menu: : style can be found in sidebar.less -->
        <ul class="sidebar-menu" data-widget="tree">
            <li class="header">MAIN NAVIGATION</li>
            <li >
                <a href="/">
                    <i class="fa fa-pie-chart"></i> <span>数据统计</span>
                </a>
            </li>
            <li class="treeview active">
                <a href="#">
                    <i class="glyphicon glyphicon-gift"></i> <span>商品管理</span>
                    <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                </a>
                <ul class="treeview-menu">
                    <li><a href="/merch/listMerch"><i class="fa fa-circle-o"></i>商品列表</a></li>
                    <li class="active"><a href="/merch/addMerch"><i class="fa fa-circle-o"></i>添加商品</a></li>
                </ul>
            </li>

            <li class="treeview">
                <a href="#">
                    <i class="glyphicon glyphicon-send"></i>
                    <span>供应商管理</span>
                    <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                </a>
                <ul class="treeview-menu">
                    <li><a href="/provider/list"><i class="fa fa-circle-o"></i>供应商列表</a></li>
                    <li><a href="/provider/addProvider"><i class="fa fa-circle-o"></i>添加供应商</a></li>
                </ul>
            </li>
            <li class="treeview">
                <a href="#">
                    <i class="fa fa-laptop"></i>
                    <span>入库管理</span>
                    <span class="pull-right-container">
                            <i class="fa fa-angle-left pull-right"></i>
                        </span>
                </a>
                <ul class="treeview-menu">
                    <li><a href="/instock/list"><i class="fa fa-circle-o"></i>入库记录</a></li>
                    <li><a href="/instock/add"><i class="fa fa-circle-o"></i>添加记录</a></li>
                </ul>
            </li>
            <li class="treeview">
                <a href="#">
                    <i class="glyphicon glyphicon-shopping-cart"></i> <span>销售管理</span>
                    <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                </a>
                <ul class="treeview-menu">
                    <li><a href="/sale/getAll"><i class="fa fa-circle-o"></i>订单列表</a></li>
                    <li><a href="/sale/adds"><i class="fa fa-circle-o"></i>添加订单</a></li>
                </ul>
            </li>
            <li class="treeview">
                <a href="#">
                    <i class="glyphicon glyphicon-user"></i> <span>会员管理</span>
                    <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                </a>
                <ul class="treeview-menu">
                    <li><a href="/member/list"><i class="fa fa-circle-o"></i>会员列表</a></li>
                    <li><a href="/member/add"><i class="fa fa-circle-o"></i>添加会员</a></li>
                </ul>
            </li>
            <li class="treeview">
                <a href="#">
                    <i class="fa fa-calendar"></i> <span>员工管理</span>
                    <span class="pull-right-container">
                <i class="fa fa-angle-left pull-right"></i>
              </span>
                </a>
                <ul class="treeview-menu">
                    <li><a href="/staff/listStaff"><i class="fa fa-circle-o"></i>员工列表</a></li>
                    <li><a href="/staff/addStaff"><i class="fa fa-circle-o"></i>添加员工</a></li>
                </ul>
            </li>
        </ul>
    </section>
    <!-- /.sidebar -->
</aside>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
    <!-- Main content -->
    <section class="content">

        <!-- Default box -->
        <div class="box">
            <div class="box-header with-border">
                <h3 class="box-title">添加商品</h3>

                <div class="box-tools pull-right">
                    <button type="button" class="btn btn-box-tool" data-widget="collapse" data-toggle="tooltip"
                            title="Collapse">
                        <i class="fa fa-minus"></i></button>
                    <button type="button" class="btn btn-box-tool" data-widget="remove" data-toggle="tooltip" title="Remove">
                        <i class="fa fa-times"></i></button>
                </div>
            </div>
            <div class="box-body">

                <div class="col-md-6">
                    <!-- general form elements -->
                    <div class="box box-primary">
                        <div class="box-header with-border">
                            <h3 class="box-title">新商品：</h3>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        <form role="form" id="addFrom">
                            <div class="box-body">
                                <div class="form-group">
                                    <label for="updateMerchName">商品姓名</label>
                                    <input class="form-control" id="updateMerchName" name="merchName" type="text" placeholder="必填"/>
                                </div>
                                <div class="form-group">
                                    <label for="updateMerchNumber">商品数量</label>
                                    <input class="form-control" id="updateMerchNumber" name="merchNumber" type="text" placeholder="必填"/>
                                </div>
                                <div class="form-group">
                                    <label for="updateupperNumber">商品数量上限</label>
                                    <input class="form-control" id="updateupperNumber" name="upperNumber"  type="text" value="1000"/>
                                </div>
                                <div class="form-group">
                                    <label for="updatelowerNumber">商品数量下限</label>
                                    <input class="form-control" id="updatelowerNumber" name="lowerNumber" type="text"  value="1"/>
                                </div>
                                <div class="form-group">
                                    <label for="updateMerchPrice">商品价格</label>
                                    <input class="form-control" id="updateMerchPrice" name="merchPrice" placeholder="请输入商品价格" type="text"/>
                                </div>
                            </div>
                            <!-- /.box-body -->

                            <div class="box-footer">
                                <button type="submit" id="addMerch" class="btn btn-primary">添加商品</button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
        <!-- /.box -->

    </section>
    <!-- /.content -->
</div>
<!-- /.content-wrapper -->
</body>
<!-- jQuery 3 -->
<script src="../../bower_components/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap 3.3.7 -->
<script src="../../bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="../../bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
<script src="../../bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
<!-- SlimScroll -->
<script src="../../bower_components/jquery-slimscroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="../../bower_components/fastclick/lib/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="../../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../../dist/js/demo.js"></script>
<!-- page script -->
<script>
    $(document).ready(function () {
        $('#addMerch').click(function () {
            var msg = "你确定要添加吗";
            if (confirm(msg) == true){
                var updateData = $("#addFrom").serializeArray();
                var data = "{";
                for (var i = 0; i < updateData.length; i++) {
                    var name = updateData[i].name;
                    var value = updateData[i].value;
                    data = data + "\"" + name + "\":\"" + value.trim() + "\",";
                }
                data = data.substring(0, data.length - 1);
                data = data + "}";
                console.log(data);
                $.ajax({
                    url: "/merch/add",
                    contentType: 'application/json',
                    dataType: "json",
                    type: "post",
                    data: data,
                    success: function (status) {
                        if (status.code == 1) {
                            $('#updateModal').modal('hide');
                            alert("add success");
                            window.location.reload();
                        } else {
                            alert("add failed");
                        }
                    },
                    error: function (data) {
                        $('#updateModal').modal('hide');
                        alert("add ok");
                        window.location.reload();
                    }
                });

            }
        });

    })
</script>
</html>